package com.test.base.service;

import com.test.base.dao.NideshopGoodsSpecificationDao;
import com.test.base.entity.NideshopGoodsSpecification;
import com.test.base.utils.Assist;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品对应规格表值表
 */
@Service
public class GoodsSepcifitionService {

    @Autowired
    private NideshopGoodsSpecificationDao specificationDao;

    public String get(Long goodsId, String[] goodsSpecificationIds) {
        Assist assist = new Assist();
        assist.setRequires(Assist.andEq("goods_id", goodsId));
        String inValue = StringUtils.join(goodsSpecificationIds, ",");
        assist.setRequires(Assist.customRequire("in (", inValue, ")"));
        List<NideshopGoodsSpecification> list = specificationDao.selectNideshopGoodsSpecification(assist);
        StringBuilder goodsSepcifitionValue = new StringBuilder();
        for(NideshopGoodsSpecification n:list){
            goodsSepcifitionValue.append(n.getValue()).append(";");
        }
        if(StringUtils.isNotEmpty(goodsSepcifitionValue)){
            goodsSepcifitionValue.delete(goodsSepcifitionValue.length()-1,goodsSepcifitionValue.length());
        }
        return goodsSepcifitionValue.toString();
    }
}
